import java.awt.Font;
import java.io.File;
import java.io.IOException;

import jxl.Workbook;
import jxl.write.WritableImage;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import ExcelUtil.ExcelUtil;


public class TestChart {
	public void Chart() throws IOException{
		 DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		 
		 dataset.addValue(5.0, "2005", "1월"); 
		 dataset.addValue(16.0, "2005", "2월"); 
		 dataset.addValue(15.0, "2005", "3월"); 
		 dataset.addValue(14.0, "2005", "4월");
		 dataset.addValue(30.0, "2005", "5월"); 
		 dataset.addValue(15.0, "2005", "6월");  
		 dataset.addValue(18.0, "2005", "7월");   
		 
		 dataset.addValue(7.0, "2006", "1월"); 
		 dataset.addValue(19.0, "2006", "2월"); 
		 dataset.addValue(9.0, "2006", "3월"); 
		 dataset.addValue(5.0, "2006", "4월"); 
		 dataset.addValue(15.0, "2006", "5월");
		 dataset.addValue(22.0, "2006", "6월"); 
		 dataset.addValue(19.0, "2006", "7월"); 
		 
		 JFreeChart chart = ChartFactory.createBarChart("Bar Chart","월", "대여량", dataset, PlotOrientation.VERTICAL, true, true, false);
		 
		 chart.setBackgroundPaint(java.awt.Color.white);
		 chart.setTitle("월별 DVD 대여량");
		 //제목
		 chart.getTitle().setFont(new Font("돋움",Font.BOLD,20));
		 //범례
		 chart.getLegend().setItemFont(new Font("돋움",Font.PLAIN,10));
		  
		 CategoryPlot plot = chart.getCategoryPlot();
		 Font font = plot.getDomainAxis().getLabelFont();
		 //x축 라벨
		 plot.getDomainAxis().setLabelFont(new Font("돋움",font.getStyle(),font.getSize()));
		 //x축 도메인
		 plot.getDomainAxis().setTickLabelFont(new Font("돋움",font.getStyle(),10));
		 
		 font = plot.getRangeAxis().getLabelFont();
		 //Y축 라벨
		 plot.getRangeAxis().setLabelFont(new Font("돋움",font.getStyle(),font.getSize()));
		 //Y축 범위
		 plot.getRangeAxis().setTickLabelFont(new Font("돋움",font.getStyle(),10));
		 
		 
		 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
		 String fileName = "C:\\MES\\img\\" + "K0001.png";
		 ChartUtilities.saveChartAsPNG(new File(fileName),chart,600,300,info);
	}
	
	public void excel() throws IOException, WriteException{
		
		String fileName= "member.xls";
		long name = System.currentTimeMillis();
		File downFile = new File("c:\\GPS\\excel\\"+"mem."+name+".xls");
		WritableWorkbook workbook = Workbook.createWorkbook(downFile);
		WritableSheet sheet = workbook.createSheet("회원정보", 0);
		sheet = ExcelUtil.excelTitle(0, 0, "회원아이디",sheet);
		sheet = ExcelUtil.excelTitle(1, 0, "회원이름",sheet);
		sheet = ExcelUtil.excelTitle(2, 0, "E-mail",sheet);
		sheet = ExcelUtil.excelTitle(3, 0, "성별",sheet);
		sheet = ExcelUtil.excelTitle(4, 0, "전화번호",sheet);
		sheet = ExcelUtil.excelTitle(5, 0, "핸드폰번호",sheet);
		sheet = ExcelUtil.excelTitle(6, 0, "관리자여부",sheet);
		sheet = ExcelUtil.excelCell(0,0,"ㅁㅇㄴㄹ",sheet);
		sheet = ExcelUtil.excelCell(1,0,"aaa", sheet);
		sheet = ExcelUtil.excelCell(2,0,"adf", sheet);
		sheet = ExcelUtil.excelCell(3,0,"Asdf", sheet);
		sheet = ExcelUtil.excelCell(4,0,"asdf", sheet);
		sheet = ExcelUtil.excelCell(5,0,"Asdf", sheet);
		sheet = ExcelUtil.excelCell(6,0,"Asdf", sheet);
		File imgFile = new File("C:\\MES\\img\\" + "K0001.png");
		WritableImage img = new WritableImage(0,2,10,15,imgFile);
		                               //행, 열, 가로, 세로
		sheet.addImage(img);
		workbook.write();
		workbook.close();
	}
	public static void main(String[] args) {
		TestChart e = new TestChart();
		try {
			e.Chart();
			e.excel();
		} catch (WriteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
	}
}
